import 'package:flutter/material.dart';

/// 上传导航栏项组件
///
/// 显示上传标签页，并在有上传任务时显示上传状态徽标
class UploadNavItem {
  /// 是否有任务
  final bool hasTasks;

  /// 正在处理的任务数量
  final int processingTasksCount;

  const UploadNavItem({
    required this.hasTasks,
    required this.processingTasksCount,
  });

  /// 获取底部导航栏项
  BottomNavigationBarItem build() {
    return BottomNavigationBarItem(
      icon: _buildIcon(false),
      activeIcon: _buildIcon(true),
      label: '上传',
    );
  }

  /// 构建图标，处理常规状态和激活状态
  Widget _buildIcon(bool isActive) {
    return Stack(
      clipBehavior: Clip.none,
      children: [
        Icon(isActive ? Icons.cloud_upload : Icons.cloud_upload_outlined),
        if (hasTasks) Positioned(right: -6, top: -6, child: _buildTaskBadge()),
      ],
    );
  }

  /// 构建任务状态徽标
  Widget _buildTaskBadge() {
    return Container(
      padding: const EdgeInsets.all(2),
      decoration: BoxDecoration(
        color: processingTasksCount > 0 ? Colors.blue : Colors.green,
        borderRadius: BorderRadius.circular(10),
      ),
      constraints: const BoxConstraints(minWidth: 14, minHeight: 14),
      child:
          processingTasksCount > 0
              ? Text(
                '$processingTasksCount',
                style: const TextStyle(color: Colors.white, fontSize: 8),
                textAlign: TextAlign.center,
              )
              : const Icon(Icons.check, size: 10, color: Colors.white),
    );
  }
}
